﻿using System;
using System.Data;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using StructureMap;
using StructureMap.Configuration.DSL;
using StructureMap.Configuration;
using StructureMap.Pipeline;
using myFinance.Domain.LinqToSql;
using myFinance.Domain;
using myFinance.Services;
using Microsoft.Practices.Unity;
using System.Data.Linq;
using System.Web.Mvc;
using myFinance.Domain.Data;
namespace myFinance.Web {

    public static class Bootstrapper {

        public static void ConfigureStructureMap() {

            StructureMap.StructureMapConfiguration.AddRegistry(new DBServiceRegistry());
            StructureMap.StructureMapConfiguration.AddRegistry(new DInjRegistry());
        }
        public static void ConfigureUnityContainer() {
            IUnityContainer container = new UnityContainer();
            // Registrations
            container.RegisterType<myFinanceData, myFinanceData>(new HttpContextLifetimeManager<myFinanceData>());
            container.RegisterType<ICategoryRepository, CategoryRepository>(new HttpContextLifetimeManager<ICategoryRepository>());
            container.RegisterType<ICategoryService, CategoryService>(new HttpContextLifetimeManager<ICategoryService>());
            ControllerBuilder.Current.SetControllerFactory(
                new myFinance.Web.Controllers.UnityControllerFactory(container));           
        }
    }

    public class DInjRegistry : Registry {
        protected override void configure() {

            ForRequestedType<ICategoryRepository>()
        .TheDefaultIsConcreteType<CategoryRepository>();

        ForRequestedType<ICategoryService>()
           .TheDefaultIsConcreteType<CategoryService>();

        }
    }
}
